package com.BianLiErChaShu;

public class Tree {

    Node root;//根节点
    int size;//树长度
    char[] data;//树的数据
    public Tree(char[] data) {
        this.data = data;
        size = data.length;
        root = createTree(0);
    }
    //创建二叉树
    public Node createTree(int index) { // 采用递归生成二叉树
        if (index >= size)
            return null;
        if (data[index] == '0')
            return null;
        Node node = new Node(data[index]);
        node.setLeft(createTree(2 * index + 1));
        node.setRight(createTree(2 * index + 2));
        return node;
    }
    public void preShow(Node node) { // 先序遍历
        if (node != null) {
            System.out.print(node.getData() + " ");
            preShow(node.getLeft());
            preShow(node.getRight());
        }
    }

    //二叉树的根的值
    public Node getRoot() {
        return root;
    }
}
